xenstore: Redirect stdin/stdout/stderr to /dev/null.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 1 Aug 2007 18:34:56 +0000 (19:34 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 1 Aug 2007 18:34:56 +0000 (19:34 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/xenstore/xenstored_core.c

index a969bcff56e49a05bd66bf8d23a88cd22b79fcaf..e68004ad05bc288b0d6b4e3e4c35654586f80fab 100644 (file)
@@ -1880,10 +1880,14 @@ int main(int argc, char *argv[])
 
        /* close stdin/stdout now we're ready to accept connections */
        if (dofork) {
-               close(STDIN_FILENO);
-               close(STDOUT_FILENO);
-               close(STDERR_FILENO);
-               xprintf = trace; /* xprintf() must not use stderr */
+               int devnull = open("/dev/null", O_RDWR);
+               if (devnull == -1)
+                       barf_perror("Could not open /dev/null\n");
+               close(STDIN_FILENO);  dup2(STDIN_FILENO, devnull);
+               close(STDOUT_FILENO); dup2(STDOUT_FILENO, devnull);
+               close(STDERR_FILENO); dup2(STDERR_FILENO, devnull);
+               close(devnull);
+               xprintf = trace;
        }
 
        signal(SIGHUP, trigger_reopen_log);